package servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Employee;
import model.Timesheet;
import service.Constan;
import service.implement.EmployeeDAO;
import service.implement.TimesheetDAO;

/**
 * Servlet implementation class doupdateTimesheet
 */
@WebServlet("/doupdateTimesheet")
public class doupdateTimesheet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public doupdateTimesheet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int employeeid=Integer.parseInt(request.getParameter("employeeid"));
		int projectid=Integer.parseInt(request.getParameter("projectid"));
		String date=request.getParameter("date");
		int id = Integer.parseInt(request.getParameter("id2"));
		int duration=Integer.parseInt(request.getParameter("duration"));
		String description=request.getParameter("description");
		String activity=request.getParameter("activity");
		String overtime=request.getParameter("overtime");
		String location=request.getParameter("location");
		Timesheet ts=new Timesheet(id,date,duration,description,activity,overtime,location,employeeid,projectid);
		TimesheetDAO dao=new TimesheetDAO();
		if(dao.updateTimesheet(ts)==Constan.SER_STATUS_SUCSESS){
			RequestDispatcher rd = request.getRequestDispatcher("listTimesheet.jsp");
			rd.forward(request, response);
		}
		else{
			RequestDispatcher rd=request.getRequestDispatcher("updateTimesheet.jsp");
			rd.forward(request, response);
		}
	}

}
